package org.jasper.example.sudoku;

import org.jasper.api.container.FactHandle;
import org.jasper.api.container.KieContainer;
import org.jasper.api.listerner.RuleRuntimeEventListener;
import org.jasper.api.session.KieSession;

/**
 * Created by OP038074 on 2018/7/26.
 */
public class Sudoku implements SudokuGridModel {

    private KieContainer kc;
    private KieSession session;
    private FactHandle steppingFactHandle;
    public static Sudoku sudoku;
    private SudokuWorkingMemoryListener workingMemoryListener = new SudokuWorkingMemoryListener();

    public Sudoku(KieContainer kc) {
        this.kc = kc;
        sudoku = this;
    }

    public void setCellValues(Integer[][] cellValues) {
        if (session != null) {
            session.removeEventListener(workingMemoryListener);
            session.dispose();
            steppingFactHandle = null;
        }
        this.session = kc.newKieSession("SudokuKS");
    }

    public void validate(){
        session.getAgenda().getAgendaGroup( "validate" ).setFocus();
        session.fireUntilHalt();
    }

    class SudokuWorkingMemoryListener implements RuleRuntimeEventListener {

    }
}
